package com.leyou.common.vo;

import com.leyou.common.enums.ExceptionEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> {
    private Boolean flag;
    private int code;
    private String msg;
    private T data;

    private static final int SUCCESS_CODE = 200;

    public static <T> ResponseResult<T> body(boolean flag, int code, String msg, T data) {
        return new ResponseResult<>(flag, code, msg, data);
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(true, SUCCESS_CODE, null, data);
    }

    public static <T> ResponseResult<T> fail(int code, String msg) {
        return new ResponseResult<>(false, code, msg, null);
    }

    public static <T> ResponseResult<T> fail(ExceptionEnum e) {
        return new ResponseResult<>(false, e.getCode(), e.getMsg(), null);
    }
}
